package com.ftg.learn.chapter04;

import java.util.Arrays;

/**
 * 数列
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/5/27 下午2:37
 */
public class FBNQ {

    public static void main(String[] args) {
        int[] a1 = printFBNQ1(10);
        System.out.println(Arrays.toString(a1));
    }

    /**
     * 循环打印
     *
     * @param count
     */
    public static void printFBNQ(int count) {
        long start = 1;
        long second = 1;
        System.out.print(start + "\t");
        System.out.print(second + "\t");
        int index = 2;
        while (index++ < count) {
            long t = start + second;
            System.out.print(start + second + "\t");
            start = second;
            second = t;
        }
    }

    /**
     * 好理解
     * @param count
     */
    public static int[] printFBNQ1(int count) {
        int[] arr = new int[count];
        arr[0] = 1;
        arr[1] = 1;
        for (int i = 2; i < count; i++) {
            arr[i] = arr[i - 1] + arr[i - 2];
        }
        return arr;
    }

    /**
     * 递归
     *
     * @param a 位置
     * @return 数
     */
    public static int fibonacci(int a) {
        int num = 0;
        if (a == 1 || a == 2) {
            num = 1;
            return num;
        } else {
            return fibonacci(a - 1) + fibonacci(a - 2);
        }
    }
}
